package BookManagement.operation;

import BookManagement.book.Bookshelf;

import java.sql.SQLOutput;
import java.util.Scanner;

public class BorrowingBook implements IBusinessOperation{
    @Override
    public void work(Bookshelf bookshelf) {
        System.out.println("借阅图书……");
        System.out.println("请用户输入要借阅的书籍名称：");
        String name = "";
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();
        int number = bookshelf.book_umber;
        //先查找用户借阅的书籍是否存在或者是否已经借出
        int i = 0;
        for(;i<number; i++){
            if(name.equals(bookshelf.books[i].getName()) && !bookshelf.books[i].getStatus()){
                //书籍存在并且没被借出
                //此时修改书籍的借阅状态
                System.out.println("书籍已借阅！");
                bookshelf.books[i].setStatus(true);
                System.out.println(bookshelf.books[i]);
                break;
            }
            else if(name.equals(bookshelf.books[i].getName())){
                //用户要借阅的书籍已经被借出，无法再次借阅
                System.out.println("此书已经被借出！请选择未被借阅的书籍：");
                break;
            }
        }
        if(i >= number){
            System.out.println("要借阅的书籍未找到，无法借阅，请选择存在且未被借阅的书籍：");
        }
    }
}
